<html>
	<head>
    	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    </head>
    <body>
    	<?php
			session_start();
			if(!isset($_REQUEST["guess"])){
				session_destroy();
				session_start();
			}
			if(isset($_REQUEST["level"])){
				$level = $_REQUEST["level"];
				if($level == 1){
					$lvl = 100;
					echo "level 1";
				}
				else if($level == 2){
					$lvl = 1000;
					echo "level 2";
				}
				else if($level == 3){
					$lvl = 10000;
					echo "level 3";
				}
			}
			else{
					$lvl = 50;
			}
			if(!isset($_SESSION["random"])){
				$count = 0;
				$_SESSION["count"] = $count;
				$random = rand(1,$lvl);
				$_SESSION["random"] = $random;
				}
			else{
				$count = $_SESSION["count"];
				$random = $_SESSION["random"];
			}
			if(isset($_REQUEST["guess"])){
				$guess = $_REQUEST["guess"];
				if($guess < $random){
					echo "For lavt";
				}
				else if($guess > $random){
					echo "For højt";
				}
				else if($guess == $random){
					echo "KORREKT!";
				}
				$count++;
				$_SESSION["count"] = $count;
				echo "<br>Du har brugt: $count gæt";
			}
			
			echo $level;
		?>
        <form action="numberguesser.php?level=<?php echo $level ?>">
        	<input type="text" name="guess"/>
            <input type="submit" value="ok"/>
		</form>
        <footer>&copy; Frederik Mattern</footer>
    </body>
</html>